package ch.zbw.pra.sysventory.dataaccess.dataAccessObject;

import java.io.Serializable;
import java.util.List;

import org.springframework.context.ApplicationContext;

import ch.zbw.pra.sysventory.database.jdbcTemplate.NicJDBCTemplate;
import ch.zbw.pra.sysventory.model.Nic;
import ch.zbw.pra.sysventory.utils.DatabaseUtils;

/**
 * Bereitet Daten für den Zugriff auf die Datenbank im DatabaseLayer auf
 * 
 * @author Ralph Koster & Roberto Lucas
 */

public class NicDataAccessObject implements Serializable{

	private static final long serialVersionUID = 8482138619382945007L;
	
	private ApplicationContext context;
	private NicJDBCTemplate nicJDBCTemplate;
	
	public NicDataAccessObject() {
		context = DatabaseUtils.getContext();
		nicJDBCTemplate = (NicJDBCTemplate)context.getBean("nic");
	}

	public List<Nic> getAllNicFromDatabase() {
		List<Nic> nics = nicJDBCTemplate.listNics();
		return nics;
	}

	public List<Nic> getAllNicsFromComputer(Integer computerId) {
		List<Nic> nics = nicJDBCTemplate.listAllNicsFromComputer(computerId);
		return nics;
	}

	public Integer writeNicsToDatabase(List<Nic> nics, Integer computerId) {
		Integer nicId = null;
		for(Nic nic:nics){
		nicId = nicJDBCTemplate.insertNicJDBCTemplate(nic, computerId);
		}
		return nicId;
	}
}
